﻿
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="d" uri="/WEB-INF/resource.tld" %>

<sec:authentication property="principal" var="currentPrincipal" scope="page" />

<fmt:setBundle basename="ApplicationMessage" />
<fmt:setLocale value="zh_CN" />

<!DOCTYPE html>
<html lang="zh-CN">
<head>

  <%@ include file="/WEB-INF/include/meta.jsp"%>
  <%@ include file="/WEB-INF/include/css.jsp"%>
  
</head>

<body>

  <%@ include file="/WEB-INF/include/header.jsp"%>
  
  <%@ include file="/WEB-INF/include/menu.jsp"%>

  <div class="container main-content">

    <div class="panel panel-default x-panel x-panel-layout">

      <div class="panel-heading">
        <ol class="breadcrumb">
          <li><a href="${ctx.host}/system">电商管理</a></li>
          <li class="active">课程管理</li>
        </ol>
      </div>

      <div class="panel-body">

        <div class="col-xs-2 x-panel-layout-left no-horizontal-padding">
          <%@ include file="/WEB-INF/include/submenu.jsp"%>
        </div>

        <div class="col-xs-10 x-panel-layout-right">

          <div class="x-breadcrumb-wrapper">
            <div class="x-breadcrumb clearfix">
              <h2><i class="glyphicon glyphicon-fire" title=""></i>&nbsp;&nbsp;<span>课程管理&nbsp;-&nbsp;排期表</span></h2>
              <div class="pull-right">
                <c:choose>
                  <c:when test="${not empty currentPrincipal.site}">
                    <span class="current-branchCode">${currentPrincipal.site.name}</span>
                  </c:when>
                  <c:otherwise>
                    <select name="site">
                      <option value="">所有门店</option>
                      <c:forEach var="site" items="${persist.getSites(currentPrincipal.id)}">
                        <option value="${site.id}" ${site.id == param.site ? 'selected' : ''}>${site.name}</option>
                      </c:forEach>
                    </select>
                  </c:otherwise>
                </c:choose>
              </div>
            </div>
          </div>
          
          <div class="form-horizontal clearfix" >
            
            <div class="btn-group pull-right" role="group" aria-label="..." style="margin-left: 30px;">
              <a href="${ctx.host}/schedules?site=${site.id}" class="btn ${coachview eq 'true' ? 'btn-success' : 'btn-default' }">教练</a>
              <a href="${ctx.host}/schedules?coachview=false&site=${site.id}" class="btn ${coachview eq 'false' ? 'btn-success' : 'btn-default' }">日期</a>
            </div>
            
            <div class="btn-group pull-right">
              <a href="${ctx.host}/schedules/search${not empty queryString ? '?' : ''}${queryString}" data-target="#" data-toggle="modal" class="btn btn-default x-btn btn-shadow btn-shadow-default">
                <i class="glyphicon glyphicon-search"></i>&nbsp;&nbsp;过滤查询
              </a>
            </div>
            
          </div>
          
          <c:if test="${coachview eq 'true'}">
            <c:forEach var="weekDates" items="${dates}">
              <table class="table table-bordered schedule-table text-center" style="margin-top: 20px;">
                <thead>
                  <tr>
                    <th class="text-center" colspan="13" style="background-color: #69AB1F; color: #fff;">${weekDates.key}</th>
                  </tr>
                </thead>
                <tbody>
                  <c:forEach var="principal" items="${persist.coaches(currentPrincipal.id, param.site)}">
                    <c:if test="${principal.value.coach}">
                      <c:choose>
                        <c:when test="${not empty param.coachId}">
                          <c:if test="${principal.key eq param.coachId}">
                            <c:forEach var="date" items="${weekDates.value}" varStatus="status">
                              <tr>
                                <c:if test="${status.index eq 0}">
                                  <td rowspan="7" style="text-align: center; vertical-align: middle; font-size: 16px; width: 100px; background-color: #E8E8E8;">${principal.value.name}</td>
                                </c:if>
                                <td><fmt:formatDate value="${date}" /></td>
                                <fmt:formatDate value="${date}" pattern="yyyy-MM-dd" var="day"></fmt:formatDate>
                                <c:forEach var="hour" begin="10" end="20">
                                  <c:set var="dayhour" value="${day}|${hour}:00"></c:set>
                                  <c:choose>
                                   <c:when test="${not empty courseSchedules[principal.key][dayhour] and courseSchedules[principal.key][dayhour][0].courseType.group}">
                                    <td class="group">${hour}:00</td>
                                   </c:when>
                                   <c:when test="${not empty courseSchedules[principal.key][dayhour] and courseSchedules[principal.key][dayhour][0].courseType.individual}">
                                     <td class="individual">${hour}:00</td>
                                   </c:when>
                                   <c:when test="${not empty restSchedules[principal.key][dayhour]}">
                                     <td class="rest">${hour}:00</td>
                                   </c:when>
                                   <c:otherwise>
                                     <td>${hour}:00</td>
                                   </c:otherwise>
                                  </c:choose>
                                </c:forEach>
                              </tr>
                            </c:forEach>
                          </c:if>
                        </c:when>
                        <c:otherwise>
                          <c:forEach var="date" items="${weekDates.value}" varStatus="status">
                            <tr>
                              <c:if test="${status.index eq 0}">
                                <td rowspan="7" style="text-align: center; vertical-align: middle; font-size: 16px; width: 100px; background-color: #E8E8E8;">${principal.value.name}</td>
                              </c:if>
                              <td><fmt:formatDate value="${date}" /></td>
                              <fmt:formatDate value="${date}" pattern="yyyy-MM-dd" var="day"></fmt:formatDate>
                              <c:forEach var="hour" begin="10" end="20">
                                <c:set var="dayhour" value="${day}|${hour}:00"></c:set>
                                <c:choose>
                                 <c:when test="${not empty courseSchedules[principal.key][dayhour] and courseSchedules[principal.key][dayhour][0].courseType.group}">
                                  <td class="group">${hour}:00</td>
                                 </c:when>
                                 <c:when test="${not empty courseSchedules[principal.key][dayhour] and courseSchedules[principal.key][dayhour][0].courseType.individual}">
                                   <td class="individual">${hour}:00</td>
                                 </c:when>
                                 <c:when test="${not empty restSchedules[principal.key][dayhour]}">
                                   <td class="rest">${hour}:00</td>
                                 </c:when>
                                 <c:otherwise>
                                   <td>${hour}:00</td>
                                 </c:otherwise>
                                </c:choose>
                              </c:forEach>
                            </tr>
                          </c:forEach>
                        </c:otherwise>
                      </c:choose>
                    </c:if>
                  </c:forEach>
                </tbody>
              </table>
            </c:forEach>
          </c:if>

          <c:if test="${coachview eq 'false'}">
            <c:forEach var="weekDates" items="${dates}">
              <table class="table table-bordered schedule-table text-center" style="margin-top: 20px;">
                <thead>
                  <tr>
                    <th class="text-center" colspan="13" style="background-color: #69AB1F; color: #fff;">${weekDates.key}</th>
                  </tr>
                </thead>
                <tbody>
                  <c:forEach var="date" items="${weekDates.value}" varStatus='status'>
                    <tr>
                      <td rowspan="${param.coachId != null ? 1 : persist.coaches(currentPrincipal.id, param.site).size()}" style="text-align: center; vertical-align: middle; font-size: 16px; width: 100px; background-color: #E8E8E8;"><fmt:formatDate value="${date}" /></td>
                      <c:forEach var="principal" items="${persist.coaches(currentPrincipal.id, param.site)}" varStatus="status">
                        <c:choose>
                          <c:when test="${not empty param.coachId}">
                            <c:if test="${principal.key eq param.coachId}">
                              <td>${principal.value.name}</td>
                              <fmt:formatDate value="${date}" pattern="yyyy-MM-dd" var="day" />
                              <c:forEach var="hour" begin="10" end="20">
                                <c:set var="dayhour" value="${day}|${hour}:00"></c:set>
                                <c:choose>
                                  <c:when test="${not empty courseSchedules[principal.key][dayhour] and courseSchedules[principal.key][dayhour][0].courseType.group}">
                                   <td class="group">${hour}:00</td>
                                 </c:when>
                                 <c:when test="${not empty courseSchedules[principal.key][dayhour] and courseSchedules[principal.key][dayhour][0].courseType.individual}">
                                   <td class="individual">${hour}:00</td>
                                 </c:when>
                                 <c:when test="${not empty restSchedules[principal.key][dayhour]}">
                                   <td class="rest">${hour}:00</td>
                                 </c:when>
                                 <c:otherwise>
                                   <td>${hour}:00</td>
                                 </c:otherwise>
                                </c:choose>
                              </c:forEach>
                            </c:if>
                          </c:when>
                          <c:otherwise>
                            <c:if test="${status.index eq 0}">
                              <td>${principal.value.name}</td>
                              <fmt:formatDate value="${date}" pattern="yyyy-MM-dd" var="day" />
                              <c:forEach var="hour" begin="10" end="20">
                                <c:set var="dayhour" value="${day}|${hour}:00"></c:set>
                                <c:choose>
                                  <c:when test="${not empty courseSchedules[principal.key][dayhour] and courseSchedules[principal.key][dayhour][0].courseType.group}">
                                   <td class="group">${hour}:00</td>
                                 </c:when>
                                 <c:when test="${not empty courseSchedules[principal.key][dayhour] and courseSchedules[principal.key][dayhour][0].courseType.individual}">
                                   <td class="individual">${hour}:00</td>
                                 </c:when>
                                 <c:when test="${not empty restSchedules[principal.key][dayhour]}">
                                   <td class="rest">${hour}:00</td>
                                 </c:when>
                                 <c:otherwise>
                                   <td>${hour}:00</td>
                                 </c:otherwise>
                                </c:choose>
                              </c:forEach>
                            </c:if>
                          </c:otherwise>
                        </c:choose>
                      </c:forEach>
                    </tr>
                    <c:if test="${empty param.coachId}">
                      <c:forEach var="principal" items="${persist.coaches(currentPrincipal.id, param.site)}" begin="1">
                        <tr>
                          <td>${principal.value.name}</td>
                          <fmt:formatDate value="${date}" pattern="yyyy-MM-dd" var="day" />
                          <c:forEach var="hour" begin="10" end="20">
                            <c:set var="dayhour" value="${day}|${hour}:00"></c:set>
                            <c:choose>
                              <c:when test="${not empty courseSchedules[principal.key][dayhour] and courseSchedules[principal.key][dayhour][0].courseType.group}">
                               <td class="group">${hour}:00</td>
                             </c:when>
                             <c:when test="${not empty courseSchedules[principal.key][dayhour] and courseSchedules[principal.key][dayhour][0].courseType.individual}">
                               <td class="individual">${hour}:00</td>
                             </c:when>
                             <c:when test="${not empty restSchedules[principal.key][dayhour]}">
                               <td class="rest">${hour}:00</td>
                             </c:when>
                             <c:otherwise>
                               <td>${hour}:00</td>
                             </c:otherwise>
                            </c:choose>
                          </c:forEach>
                        </tr>
                      </c:forEach>
                    </c:if>
                  </c:forEach>
                </tbody>
              </table>
            </c:forEach>
          </c:if>
          
        </div>

      </div>

    </div>

  </div>

  <%@ include file="/WEB-INF/include/footer.jsp"%>
  <%@ include file="/WEB-INF/include/script.jsp"%>
  <d:resource root="${ctx.resource}/build" type="script" src="js/page/course/schedule-index.js">
    <script type="text/javascript">
      var coachview = "${param.coachview}";
      var beginDate = "${param.beginDate}";
      var weekOffset = "${param.weekOffset}";
      var coachId = "${param.coachId}";
      require(['page/course/schedule-index'], function(page) {
        page.init({
          "coachview" : coachview,
          "beginDate" : beginDate,
          "weekOffset": weekOffset,
          "coachId" : coachId
        })
      })
    </script>
  </d:resource>

</body>

</html>
